package com.yaorange.controlller;

import com.yaorange.entity.AssociationCouncil;
import com.yaorange.response.Result;
import com.yaorange.service.AssociationCouncilService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @Author 江就
 * @Version 1.0
 * @Date 2025/6/25
 * @Description 协会理事会成员信息Controller
 */
@RestController
@RequestMapping("/associationCouncils")
public class AssociationCouncilController {

    @Resource private AssociationCouncilService associationCouncilService;

    /**
     * 插入协会理事会成员信息
     */
    @PostMapping
    public Result<?> insert(@RequestBody AssociationCouncil council) {
        int result = associationCouncilService.insert(council);
        return result > 0 ? Result.success("插入成功", null) : Result.fail("插入失败");
    }

    /**
     * 根据主键更新协会理事会成员信息
     */
    @PutMapping("/{id}")
    public Result updateById(@PathVariable Long id, @RequestBody AssociationCouncil council) {
        council.setId(id);
        int result = associationCouncilService.updateById(council);
        return result > 0 ? Result.success("更新成功", null) : Result.fail("更新失败");
    }

    /**
     * 根据主键删除协会理事会成员信息
     */
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable Long id) {
        AssociationCouncil AssociationCouncil = new AssociationCouncil();
        AssociationCouncil.setId(id);
        AssociationCouncil.setDelFlag(1);
        int result = associationCouncilService.updateById(AssociationCouncil);
        return result > 0 ? Result.success("删除成功", null) : Result.fail("删除失败");
    }

    /**
     * 根据主键查询协会理事会成员信息
     */
    @GetMapping("/{id}")
    public Result<?> selectById(@PathVariable Long id) {
        AssociationCouncil council = associationCouncilService.selectById(id);
        return council != null ? Result.success(council) : Result.fail("未找到对应记录");
    }

    /**
     * 查询所有协会理事会成员信息
     */
    @GetMapping
    public Result<?> selectAll(AssociationCouncil query) {
        return Result.success(associationCouncilService.selectAll(query));
    }

    /**
     * 分页查询协会理事会成员信息
     */
    @GetMapping("/page")
    public Result selectPage(AssociationCouncil query,
                             @RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10") Integer size) {
        return Result.success(associationCouncilService.selectPage(query, page, size));
    }
}
